package com.qianji.petmall.order.web;

import com.qianji.petmall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * @author liang zai
 * @date 2022/4/22 18:15
 * @description
 */
@Controller
public class HelloController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ResponseBody
    @GetMapping("ack")
    public String ack(OrderEntity entity){
        String uuid = UUID.randomUUID().toString();
        entity.setOrderSn(uuid);
        rabbitTemplate.convertAndSend("order-event-exchange","order.creat.order",entity);
        System.out.println("发送消息成功");
        return "ok";
    }


    @GetMapping("/{page}.html")
    public String hello(@PathVariable("page")String page){
        return page;
    }
}
